import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'), // 配置 @ 指向 src 目录
    },
  },
  server: {
    proxy: {
      '/robot': {
        target: 'http://127.0.0.1:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/robot/, ''),
        bypass(req, res, options) {
          //@ts-ignore
          const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target))?.href || '';
          req.headers['x-req-proxyUrl'] = proxyUrl
          res.setHeader('x-res-proxyUrl', proxyUrl)
        },

      }
    }
  }
})
